﻿using UnityEngine;
using System.Collections;
using System;

namespace Connections {

	public class HackCommand : ICommand {

//		private bool needResponse;
		
		public HackCommand() {
//			needResponse = false;
		}
		
		public string getCommand() {
//			needResponse = false;
			int level = UnityEngine.Random.Range (0, 512);
			MiniGameManager.getInstance ().ChangeLevel (0);
			return "launchlevel:" + level;
		}
		
		public void respond(string command, string content) {
			if(command.Equals("finishlevel")) {
				Debug.Log ("HackCommand ~> content - " + content);
				int finish = Int32.Parse(content);
				// do something with content
				Debug.Log("Client Finished with status: " + ((finish == 1) ? "Completed" : "Canceled"));
				if(finish == 1) {
					Debug.Log ("Finishing Level");
					MiniGameManager.getInstance().setLevel(0);
					MiniGameManager.getInstance().finishStatus = 1;
					//MiniGameManager.getInstance().CheckGameOver();
				} else {
					Debug.Log("Canceling Level");
					MiniGameManager.getInstance().Cancel();
				}
			}
		}
		
		public bool needsToRespond() {
			if (ServerManager.getInstance ().minigameStart) {
				ServerManager.getInstance().minigameStart = false;
				return true;
			}
			return false;
		}
	}
}
